/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

//import static digitester.GateAnd.value;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

/**
 *
 * @author pwarnimo
 */
public class GateGlobal {
    private int GateType;
    protected Point Coords;
    private int Outputs;
    private int Inputs;
    private boolean Negated;
    private boolean Selected = false;
    private int ID = -1;
    
    public static final int size = 50;
    
    public GateGlobal(int GateType, Point Coords, int Outputs, int Inputs, boolean Negated, int ID) {
        this.GateType = GateType;
        this.Coords = Coords;
        this.Outputs = Outputs + 1;
        this.Inputs = Inputs + 1;
        this.Negated = Negated;
        this.ID = ID;
        
        //System.out.println("Inputs given = " + this.Inputs);
    }
    
    public void setGateType(int GateType) {
        this.GateType = GateType;
    }
    
    public int getGateType() {
        return GateType;
    }
    
    public void setCoords(Point Coords) {
        this.Coords = Coords;
    }
    
    public Point getCoords() {
        return Coords;
    }
    
    public int getID() {
        return ID;
    }
    
    public void paintGate(Graphics2D g2) {
        g2.drawRect(Coords.x + 5, Coords.y, size - 10, size);
        g2.drawString("ID" + ID, Coords.x + 6, Coords.y + 11);
        
        if (Selected) {
            g2.setColor(Color.cyan);
            g2.fillRect(Coords.x + 5, Coords.y, size - 10, size);
            g2.setColor(Color.black);
        }
        
        int offsetInput = size / Inputs;
        int offsetOutput = size / Outputs;
        int curr = 0;
        
        //System.out.println("Size = " + size + " Inputs = " + (Inputs -1) +" Offset = " + offsetInput);
        
        for (int i = 1; i <= Inputs; i++) {
            if (i != 1) {
                g2.drawLine(Coords.x, Coords.y + ((curr)), Coords.x + 5, Coords.y + ((curr)));
            }            
            curr += offsetInput;
        }
        
        curr = 0;
        
        for (int i = 1; i <= Outputs; i++) {
            if (i != 1) {
                g2.drawLine(Coords.x + (size - 5), Coords.y + ((curr)), Coords.x + size, Coords.y + ((curr)));
                if (Negated == true) {
                    g2.fillOval(Coords.x + (size - 7), Coords.y + curr - 3, 6, 6);
                }
            }            
            curr += offsetOutput;
        }
    }
    
    public void select() {
        Selected = !Selected;
    }
}
